iT邦幫忙

2025 iThome 鐵人賽

DAY 2
0

環境設置

為了簡單清楚地體驗 MCP(Model Context Protocol),我選擇了以下環境:
https://ithelp.ithome.com.tw/upload/images/20250917/20178248yHeFIydZ6H.png

  • 開發工具:VS Code + Roo Code

    Roo Code 是一個 VS Code 擴充,支援 MCP,可以直接設定 MCP server,不用額外啟動外部客戶端,最直觀。

  • 模型選擇:OpenRouter 上的 GPT-4o mini

    這個模型免費或低成本,回應速度快,很適合當 MCP 的 Host 端 Agent 來測試。

Weather MCP

MCP 的設計,是讓模型能夠透過 工具(tools) 與外部服務或資料源互動。

「Weather MCP」就是一個典型的示範:

  • 資料來源:Weather MCP API(這裡用 Open-Meteo,免金鑰、全球可用)。

  • MCP Server:把 Weather API 包裝成 MCP 工具(如 get-forecast)。

  • MCP Client(Host):像 Roo Code 或 Claude Desktop,會讀取 MCP server 提供的工具,然後在對話中呼叫。

天氣 MCP 之所以常被拿來示範,是因為它簡單、直覺,而且能快速驗證 MCP 的工具呼叫機制是否正常。

示範 & 實做

選擇一個 Github 專案。這個鐵人系列主要就是希望可以多摸索、應用、發掘社群公開好用的MCP。
目前 Github 算是開源程式的領導地位,開發者會將自己的MCP丟在上面。

我使用的範例來自這個專案:
👉 debs-obrien/mcp-weather-server-demo

理由:

  1. 免金鑰:不需要額外申請帳號或金鑰,clone 下來就能跑。
  2. 教學清楚:repo 裡示範了怎麼定義一個簡單 MCP server,適合新手理解。

安裝與測試步驟

1. Clone 專案並安裝

MCP 為AI可以操控的工具,AI要可以操控,你的電腦要先可以跑。
目前MCP工具在電腦可以跑的大宗方法為用 python 或是 node.js 跑起來。
此專案根據 Github README 教學用 node.js 跑,需先安裝 node.js / npm 環境

git clone https://github.com/debs-obrien/mcp-weather-server-demo.git
cd mcp-weather-server-demo
npm install

2. 用 MCP Inspector 測試

Inspector 是官方提供的測試工具,可以啟動並幫你接上 server。

npx -y @modelcontextprotocol/inspector npx -y tsx main.ts

3. Roo Code MCP 設定

此步驟將 Weather MCP 掛到 Roo Code,讓Roo code的AI可以使用。 編輯 mcp_settings.json
https://ithelp.ithome.com.tw/upload/images/20250917/20178248meEaS1MUpy.png

{
  "mcpServers": {
    "weather-openmeteo": {
      "command": "npx",
      "args": ["-y", "tsx", "main.ts"],
      "cwd": "D:\\T\\mcp_test\\mcp-weather-server-demo",
      "transport": "stdio"
    }
  }
}

4. 測試效果

模型會調用 weather-openmeteo MCP server 的工具,成功回傳台北未來 24 小時的天氣預報 → 測試成功 ✅
https://ithelp.ithome.com.tw/upload/images/20250917/201782484xl1hfIf0d.png

學習總結:MCP 基本知識

這個練習帶你認識 MCP 的核心概念:

1. Tools

  • 從 Roo Code 看:在聊天時,Agent 會自動挑選 get-weather 工具並帶入參數。
    https://ithelp.ithome.com.tw/upload/images/20250917/20178248d5jTVqtswX.png

  • 從 GitHub 專案看main.ts 定義了 MCP server 提供的工具,例如 get-weather
    https://ithelp.ithome.com.tw/upload/images/20250917/201782483JG6KUDMbh.png

想了解一個 MCP 可以讓 AI(LLM) 具備甚麼能力,要先看有甚麼 Tools

2. Server / Host / Client

  • MCP Server:把外部服務(Open-Meteo API)封裝成 MCP 可呼叫的工具。

  • MCP Host(Client App):像 Roo Code、Claude Desktop,負責讀取 MCP server 的能力,並在對話中調用。

  • 模型(LLM):透過 Host 來「決定何時、如何」使用這些工具。

MCP總結:debs-obrien/mcp-weather-server-demo

只有一個 Tools

  • get-weather
    • Tool to get the weather for a city

上一篇
Day1. MCP基本介紹
下一篇
Day3. Filesystem MCP
系列文
Daily MCP — Model Context Protocol in Practice3
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言